#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include<QRegExp>
#include<QRegExpValidator>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->lineEdit_name->setPlaceholderText("请输入您的姓名");
    ui->lineEdit_name->setClearButtonEnabled(true);
    //设置密码
    ui->lineEdit_pass->setPlaceholderText("请输入您的密码");
    ui->lineEdit_pass->setClearButtonEnabled(true);
    ui->lineEdit_pass->setEchoMode(QLineEdit::Password);
    //设置电话
    ui->lineEdit_phone->setPlaceholderText("请输入您的电话号码");
    ui->lineEdit_phone->setClearButtonEnabled(true);
    ui->pushButton_submit->setEnabled(false);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_submit_clicked()
{
    QString str = ui->radioButton_man->isChecked() ? "男":"女";
    qDebug()<<"您的姓名是："<<ui->lineEdit_name->text()<<
              "您的密码是: "<<ui->lineEdit_pass->text()<<
              "您的性别是："<<str<<
              "您的电话是："<<ui->lineEdit_phone->text();
}

void Widget::on_lineEdit_phone_textEdited(const QString &str)
{
    //先创建正则对象
    QRegExp rex("^1[3-9]\\d{9}$");
    QRegExpValidator validator(rex);
    int pos = 0;
    QString input = str;
    if(validator.validate(input,pos) ==QRegExpValidator::Acceptable)
    {
        ui->pushButton_submit->setEnabled(true);
    }
    else
    {
        ui->pushButton_submit->setEnabled(false);
    }
}
